package com.hyzh.latte.vehicle.nezha;

import cn.hutool.core.collection.CollectionUtil;
import com.hyzh.latte.vehicle.dmo.entity.CameraPGEntity;
import com.hyzh.latte.vehicle.dmo.entity.GatePGEntity;
import com.hyzh.latte.vehicle.dmo.entity.ParkPGEntity;
import com.hyzh.latte.vehicle.dmo.entity.PolePGEntity;
import com.hyzh.latte.vehicle.service.NezhaRecordService;
import lombok.Builder;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 * @author songkui
 * @since 2024/3/21 14:12
 */
@Data
@Builder
public class ParkDeviceBuilder {

//    private Map<String, PointPGEntity> pointMap;
    //key : parkCode;
    private Map<String, List<PoleVertex>> poleMap;
    private Map<String, List<PoleEdge>> poleEdgeMap;
    private Map<String, Map<String, CameraPGEntity>> cameraMap;
    private Map<String, Map<String,GatePGEntity>> gateMap;
    private Map<String, Map<String, PolePGEntity>> poleEntityMap;

    //key parkCode    v parkCode;
    private List<String> parkMap;
    private Map<String, ParkPGEntity> parkEntityMap;

    private Map<String, String> vtypeMap;

    private NezhaRecordService nezhaRecordService;


    public ParkDeviceBuilder verify()throws Exception{
        if (CollectionUtil.isEmpty(parkMap) || CollectionUtil.isEmpty(poleMap)
                || CollectionUtil.isEmpty(poleEdgeMap) || CollectionUtil.isEmpty(cameraMap)){
            throw new Exception("Please config  park pole  edge  camera info");
        }
        int size = parkMap.size();
        if (size != poleMap.size() || size != poleEdgeMap.size() || cameraMap.size() != size){
            throw new Exception("Please config   pole  edge  camera info");
        }

        for (String parkCode : parkMap){
            if (CollectionUtil.isEmpty(poleMap.get(parkCode))
                    || CollectionUtil.isEmpty(poleEdgeMap.get(parkCode))
                    || CollectionUtil.isEmpty(cameraMap.get(parkCode))
                    || CollectionUtil.isEmpty(poleEntityMap.get(parkCode))){
                throw new Exception("Please config  pole  edge  camera info; parkCode:" + parkCode);
            }
        }

        return this;
    }

    public void initialize() throws Exception {
        NezhaDeviceManager.getInstance().initialize(this);

    }

}
